@echo off
chcp 65001 >nul
echo ========================================
echo    Keil�����ļ���������
echo ========================================
echo.

set "KEIL_DIR=%~dp0sys\keil"

if not exist "%KEIL_DIR%" (
    echo [����] �Ҳ���KeilĿ¼: %KEIL_DIR%
    pause
    exit /b 1
)

echo [��Ϣ] KeilĿ¼: %KEIL_DIR%
echo.

:: ͳ��ɾ�����ļ�����
set /a count=0

:: ���� Listings �ļ����µ������ļ��������ļ��У�
if exist "%KEIL_DIR%\Listings" (
    echo [����] Listings �ļ���...
    for /f "delims=" %%f in ('dir /b /a-d "%KEIL_DIR%\Listings\*.*" 2^>nul') do (
        del /f /q "%KEIL_DIR%\Listings\%%f" 2>nul
        if not errorlevel 1 (
            echo   - ɾ��: %%f
            set /a count+=1
        )
    )
)

:: ���� Objects �ļ����µ��ļ������� .sct �ļ����ļ��У�
if exist "%KEIL_DIR%\Objects" (
    echo [����] Objects �ļ��� ^(���� .sct �ļ�^)...
    for /f "delims=" %%f in ('dir /b /a-d "%KEIL_DIR%\Objects\*.*" 2^>nul') do (
        set "filename=%%f"
        setlocal enabledelayedexpansion
        if /i not "!filename:~-4!"==".sct" (
            del /f /q "%KEIL_DIR%\Objects\%%f" 2>nul
            if not errorlevel 1 (
                echo   - ɾ��: %%f
                set /a count+=1
            )
        ) else (
            echo   - ����: %%f
        )
        endlocal
    )
)

:: ���� DebugConfig �ļ����µ������ļ��������ļ��У�
if exist "%KEIL_DIR%\DebugConfig" (
    echo [����] DebugConfig �ļ���...
    for /f "delims=" %%f in ('dir /b /a-d "%KEIL_DIR%\DebugConfig\*.*" 2^>nul') do (
        del /f /q "%KEIL_DIR%\DebugConfig\%%f" 2>nul
        if not errorlevel 1 (
            echo   - ɾ��: %%f
            set /a count+=1
        )
    )
)

:: ���� Keil ��Ŀ¼�µ���ʱ�ļ�
echo [����] Keil��Ŀ¼��ʱ�ļ�...

:: ɾ�� .uvguix.* �ļ����û��������ã�
for /f "delims=" %%f in ('dir /b /a-d "%KEIL_DIR%\*.uvguix.*" 2^>nul') do (
    del /f /q "%KEIL_DIR%\%%f" 2>nul
    if not errorlevel 1 (
        echo   - ɾ��: %%f
        set /a count+=1
    )
)

:: ɾ�� EventRecorderStub.scvd �ļ�
if exist "%KEIL_DIR%\EventRecorderStub.scvd" (
    del /f /q "%KEIL_DIR%\EventRecorderStub.scvd" 2>nul
    if not errorlevel 1 (
        echo   - ɾ��: EventRecorderStub.scvd
        set /a count+=1
    )
)

:: ɾ�� .bak �����ļ�������У�
for /f "delims=" %%f in ('dir /b /a-d "%KEIL_DIR%\*.bak" 2^>nul') do (
    del /f /q "%KEIL_DIR%\%%f" 2>nul
    if not errorlevel 1 (
        echo   - ɾ��: %%f
        set /a count+=1
    )
)

echo.
echo ========================================
echo [���] ������ɣ�
echo ========================================
echo.
pause

